<template>
  <div class="main">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      
    >
      <el-form-item label="提交时间" prop="createTime">
        <el-date-picker
          v-model="queryParams.submitTimeList"
          type="datetimerange"
          range-separator="至"
          format="yyyy-MM-dd HH:mm"
          value-format="yyyy-MM-dd HH:mm"
          start-placeholder="开始日期"
          size="small"
          @keyup.enter.native="handleQuery"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="提交人" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入提交人"
          clearable
          size="small"
          style="width:200px"
        />
      </el-form-item>-->
      <el-form-item label="流程状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择" clearable>
          <el-option
            v-for="item in dict.type.act_status"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <!--      <el-form-item label="采购类型" prop="projectName">-->
      <!--        <el-select v-model="queryParams.purchaseType" placeholder="请选择" clearable>-->
      <!--          <el-option-->
      <!--            v-for="item in dict.type.purchase_type"-->
      <!--            :key="item.value"-->
      <!--            :label="item.label"-->
      <!--            :value="item.value"-->
      <!--          ></el-option>-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <el-form-item label="项目名称" prop="projectName">
        <el-select v-model="queryParams.projectName" placeholder="请选择" clearable>
          <el-option
            v-for="item in projectNameInfoList"
            :key="item.value"
            :label="item.projectName"
            :value="item.projectName"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="采购事项名称" prop="itemName" label-width="120px">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="期望交付日期" prop="designDate" label-width="120px">-->
      <!--        <el-date-picker-->
      <!--          clearable-->
      <!--          v-model="queryParams.designDate"-->
      <!--          type="date"-->
      <!--          style="width: 280px;"-->
      <!--          value-format="yyyy-MM-dd"-->
      <!--          placeholder="请选择"-->
      <!--          :disabled="isdisabled"-->
      <!--          default-time="00:00:00"-->
      <!--          format="yyyy-MM-dd"-->
      <!--          @change="dateChanged"-->
      <!--          :picker-options="pickerOption"-->
      <!--        ></el-date-picker>-->
      <!--      </el-form-item>-->
      <el-form-item label="期望交付日期" prop="tripTimeList" label-width="120px">
        <el-date-picker
          v-model="queryParams.tripTimeList"
          type="daterange"
          range-separator="至"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          size="small"
          @keyup.enter.native="handleQuery"
          end-placeholder="结束日期"
          :picker-options="pickerOptionQuery"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="采购主体" prop="payUnit" >
        <el-input
          v-model="queryParams.payUnit"
          placeholder="请输入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="purchaseParityList"
      @selection-change="handleSelectionChange"
      :height="height"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="提交时间"
        align="center"
        prop="actBusinessStatus.createTime"
        width="180px"
        sortable
      />
      <el-table-column
        label="提交人"
        align="center"
        prop="actBusinessStatus.createBy"
        width="180px"
        sortable
      />
      <!--      <el-table-column label="采购类型" align="center" prop="purchaseType" sortable>-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.purchase_type" :value="scope.row.purchaseType" />-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="项目名称" align="center" prop="projectName" width="180" sortable />
      <el-table-column label="采购主体" align="center" prop="payUnit" width="180" sortable />
      <el-table-column label="采购事项名称" align="center" prop="itemName" width="180" sortable />
      <el-table-column label="期望交付日期" align="center" prop="designDate" sortable width="180" />
      <el-table-column label="流程状态" align="center" prop="actBusinessStatus.status" sortable>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.act_status" :value="scope.row.actBusinessStatus.status" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.actBusinessStatus.status==='draft' || scope.row.actBusinessStatus.status==='cancel' || scope.row.actBusinessStatus.status==='back'"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['oa:purchaseParity:edit']"
          >修改</el-button>
          <el-button
            v-if="(scope.row.actBusinessStatus.status==='draft' || scope.row.actBusinessStatus.status==='cancel' || scope.row.actBusinessStatus.status==='back') && (scope.row.createBy === userId || userId === 'admin' || userId === 'sysadmin')"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
          <el-button
            v-if="scope.row.actBusinessStatus.status==='waiting'"
            size="mini"
            type="text"
            icon="el-icon-back"
            @click="cancelProcessApply(scope.row)"
          >撤销</el-button>
          <el-button
            v-if="scope.row.actBusinessStatus.status!=='draft' || scope.row.actBusinessStatus.status==='cancel' || scope.row.actBusinessStatus.status==='back'"
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >查看</el-button>
          <el-button
            v-if="scope.row.actBusinessStatus.status!=='draft' || scope.row.actBusinessStatus.status==='cancel' || scope.row.actBusinessStatus.status==='back'"
            size="mini"
            type="text"
            icon="el-icon-download"
            @click="openPrintView(scope.row)"
          >打印</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改比价信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="80%"
      append-to-body
      :before-close="cancel"
    >
      <el-tabs type="border-card">
        <el-tab-pane label="业务单据" v-loading="loading">
          <el-form ref="form" :model="form" :rules="rules"  :inline="true">
            <el-form-item label="编号" prop="number">
              <el-input v-model="form.numberNum" disabled style="width: 280px;" />
            </el-form-item>
            <!--            <el-form-item label="采购类型" prop="number">-->
            <!--              <el-select-->
            <!--                v-model="form.purchaseType"-->
            <!--                placeholder="请选择"-->
            <!--                clearable-->
            <!--                :disabled="isdisabled"-->
            <!--              >-->
            <!--                <el-option-->
            <!--                  v-for="item in dict.type.purchase_type"-->
            <!--                  :key="item.value"-->
            <!--                  :label="item.label"-->
            <!--                  :value="item.value"-->
            <!--                ></el-option>-->
            <!--              </el-select>-->
            <!--            </el-form-item>-->
            <el-form-item label="项目名称" prop="projectName">
              <el-select
                :disabled="title!='添加比价申请'"
                v-model="form.projectName"
                placeholder="请选择"
                clearable
              >
                <el-option
                  v-for="item in projectNameList"
                  :key="item.projectName"
                  :label="item.projectName"
                  :value="item.projectName"
                ></el-option>
              </el-select>
              <!-- <el-input v-model="form.projectName" placeholder="请输入项目名称" :disabled="isdisabled" />/ -->
            </el-form-item>
            <el-form-item label="采购主体" prop="payUnit">
              <el-input
                v-model="form.payUnit"
                style="width: 280px;"
                :disabled="isdisabled"
                placeholder="请输入采购主体"
              />
            </el-form-item>
            <el-form-item label="采购事项名称" prop="itemName" label-width="120px">
              <el-input
                v-model="form.itemName"
                style="width: 280px;"
                :disabled="isdisabled"
                placeholder="请输入采购事项名称"
              />
            </el-form-item>
            <el-form-item label="期望交付日期" prop="designDate" label-width="120px">
              <el-date-picker
                clearable
                v-model="form.designDate"
                type="date"
                style="width: 280px;"
                value-format="yyyy-MM-dd"
                placeholder="请选择"
                :disabled="isdisabled"
                default-time="00:00:00"
                format="yyyy-MM-dd"
                @change="dateChanged"
                :picker-options="pickerOption"
              ></el-date-picker>
            </el-form-item>
            <br />
            <!--            <el-form-item label="物品名称" prop="objectName">-->
            <!--              <el-input v-model="form.objectName" placeholder="请输入物品名称" :disabled="isdisabled" />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="规格型号" prop="specificationModel">-->
            <!--              <el-input-->
            <!--                v-model="form.specificationModel"-->
            <!--                placeholder="请输入规格型号"-->
            <!--                :disabled="isdisabled"-->
            <!--              />-->
            <!--            </el-form-item>-->
            <!--            <el-form-item label="数量" prop="number">-->
            <!--              <el-input-->
            <!--                v-model="form.number"-->
            <!--                :disabled="isdisabled"-->
            <!--                placeholder="请输入数量"-->
            <!--                type="number"-->
            <!--                @input="form.number=form.number.replace(/\D|^0/g,'')"-->
            <!--              />-->
            <!--            </el-form-item>-->
            <el-table ref="table" :data="applyList" style="width: 100%" border :key="isUpdate">
              <el-table-column label="序号" align="center" width="55" prop="xh" type="index"></el-table-column>
              <el-table-column prop="objectName" label="物品名称" align="center" width="140">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.objectName" :disabled="isdisabled"></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="specificationModel" label="规格或型号" align="center" width="140">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.specificationModel" :disabled="isdisabled"></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="supplier" label="供应商(款式)" align="center" width="180">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.supplier" :disabled="isdisabled"></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="number" label="数量" align="center" width="140">
                <template slot-scope="scope">
                  <el-input
                    v-model="scope.row.number"
                    :disabled="isdisabled"
                    type="number"
                    @input="scope.row.number=scope.row.number.replace(/\D|^0/g,'')"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="univalence" label="单价(元)" align="center" width="210px">
                <template slot-scope="scope">
                  <el-input
                    v-model="scope.row.univalence"
                    :disabled="isdisabled"
                    style="width: 180px"
                    @input="scope.row.univalence=scope.row.univalence.replace(/^\D*([0-9]\d*\.?\d{0,2})?.*$/,'$1')"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="total" label="总价(万元)" align="center" width="180">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.total" disabled></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="payType" label="付款方式" align="center" width="200">
                <template slot-scope="scope">
                  <el-select
                    v-model="scope.row.payType"
                    :disabled="isdisabled"
                    placeholder="请选择付款方式"
                    clearable
                  >
                    <el-option
                      v-for="dict in dict.type.pay_way"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column prop="deliveryDate" label="交货期" width="250" align="center">
                <template slot-scope="scope">
                  <el-date-picker
                    v-model="scope.row.deliveryDate"
                    type="datetime"
                    :disabled="isdisabled"
                    format="yyyy-MM-dd HH:mm"
                    value-format="yyyy-MM-dd HH:mm"
                    placeholder="选择日期时间"
                  ></el-date-picker>
                </template>
              </el-table-column>
              <el-table-column fixed="right" label="操作" align="center">
                <template slot-scope="scope">
                  <el-button
                    @click.native.prevent="applaydeleteRow(scope.$index, applyList)"
                    :disabled="isdisabled"
                    size="small"
                  >移除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-row style="border:0;">
              <el-col style="text-align:center;">
                <el-button
                  :disabled="isdisabled"
                  style="border-top:none;width:100px; position: relative;bottom:2px"
                  @click="applayaddRow(applyList)"
                >+</el-button>
              </el-col>
            </el-row>
            <el-form-item
              label="比价推荐说明"
              prop="recommendedInstructions"
              label-width="120px"
              style="width: 100%"
              class="bjsm"
            >
              <el-input
                v-model="form.recommendedInstructions"
                :disabled="isdisabled"
                type="textarea"
                placeholder="请输入内容"
                style="width: 100%"
              />
            </el-form-item>
            <br />
            <el-form-item label="上传文件" prop="attachment" v-if="!(isdisabled&&!form.attachment)">
              <fileUpload v-model="form.attachment" :isDisabled="isdisabled" :limit="5" />
            </el-form-item>
            <br />
            <el-form-item label="采购照片" prop="lastWorkflow" label-width="130px">
              <image-upload v-model="form.lastWorkflow" :isDisabled="isdisabled" :limit="5" />
            </el-form-item>
          </el-form>
          <div class="dialog-footer" style="float:right" v-if="flag">
            <el-button :loading="buttonLoading" type="info" @click="submitForm('zancun')">暂存</el-button>
            <el-button :loading="buttonLoading" type="primary" @click="submitForm('submit')">提交</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-tab-pane>
        <!-- 审批历史 -->
        <el-tab-pane label="审批历史" v-if="processInstanceId">
          <history ref="historyRef" :processInstanceId="processInstanceId"></history>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
    <!-- 提交 -->
    <printForm
      ref="printForm"
      form-type="比价申请"
      :form="form"
      :history="history"
      :printObject="printObject"
      :actBusinessStatus="actBusinessStatus"
    ></printForm>
    <verify
      ref="verifyRef"
      @submitCallback="submitCallback"
      :componentName="componentName"
      :taskId="taskId"
      :taskVariables="taskVariables"
      :sendMessage="sendMessage"
    ></verify>
  </div>
</template>

<script>
import printForm from "@/views/components/printForm.vue";
import { getDept } from "@/api/system/role";
import {
  listPurchaseParity,
  getPurchaseParity,
  delPurchaseParity,
  addPurchaseParity,
  updatePurchaseParity,
  getProjectList
} from "@/api/oa/purchaseParity";
import history from "@/components/Process/History";
import verify from "@/components/Process/Verify";
import processApi from "@/api/workflow/processInst";
import { parseTime } from "@/utils/ruoyi";
import { listByIds } from "@/api/system/oss";

export default {
  props: {
    projectNameInfoList: Array,
    projectNameByList: String
  },
  name: "PurchaseParity",
  dicts: ["act_status", "purchase_type", "pay_way"],
  components: {
    history,
    verify,
    printForm
  },
  data() {
    return {
      componentName: "比价申请",
      printObject: [],
      history: [],
      actBusinessStatus: {},
      isUpdate: true,
      height: `calc(100% - 88px)`,
      applyList: [{}],
      tableData1: [], //表单属性
      isdisabled: false,
      bcbtn: true,
      infoId: "",
      xh1: "",
      // 流程实例
      processInstanceId: "",
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      pickerOptionQuery: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 比价信息表格数据
      purchaseParityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tripTimeList: [], //出差时间范围
        payUnit: undefined,
        startDate: undefined, //开始日期
        endDate: undefined, //结束日期
        projectName: undefined,
        itemName: undefined,
        designDate: undefined,
        submitTimeList: [],
        createBy: "",
        status: ""
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [{ required: true, message: "主键不能为空", trigger: "blur" }],
        projectName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" }
        ],
        payUnit: [
          { required: true, message: "采购主体不能为空", trigger: "blur" }
        ],
        itemName: [
          { required: true, message: "采购事项名称不能为空", trigger: "blur" }
        ],
        designDate: [
          { required: true, message: "期望交付日期不能为空", trigger: "blur" }
        ],
        recommendedInstructions: [
          { required: true, message: "比价推荐说明不能为空", trigger: "blur" }
        ]
      },
      taskVariables: {}, //流程变量
      taskId: undefined, //任务id
      flag: true,
      // 消息提醒
      sendMessage: {},
      processKey: "oa_purchase_parity",
      maximumValue: 0,
      userId: "",
      projectNameList: [],
      // 出差日期的可选范围
      pickerOption: {
        disabledDate: time => {
          return time.getTime() <= Date.now() - 8.64e7;
        }
      }
    };
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      if (this.projectNameByList) {
        this.handleAdd();
        this.form.projectName = this.projectNameByList;
        this.$emit('deleteProjectName');
      }
      this.getList();
      let formHeight = this.$refs.queryForm.$el.offsetHeight;
      this.height = `calc(100% - ${formHeight}px - 88px)`;
    }, 300);
    window.onresize = () => {
      let formHeight = this.$refs.queryForm.$el.offsetHeight;
      this.height = `calc(100% - ${formHeight}px - 88px)`;
    };
    this.userId = this.$store.state.user.name;
  },
  watch: {
    applyList: {
      handler() {
        //这是vue的规定写法，当你watch的值发生变化的时候，就会触发这个handler，这是vue内部帮你做的事情
        this.applyList.map(d => {
          if (d.univalence && d.number) {
            let a =
              (Math.round(d.univalence * 100) / 100) * Math.round(d.number);
            d.total = Math.round(a * 100) / 1000000;
            if (this.maximumValue < d.total) {
              this.maximumValue = d.total;
              console.log(this.applyList + "" + 2);
            }
          } else {
            console.log(2);
            d.total = 0;
          }
        });
      },
      deep: true, // 可以深度检测到 obj 对象的属性值的变化
      immediate: true //刷新加载  立马触发一次handler
    }
    // form: {
    //   handler() {
    //       //这是vue的规定写法，当你watch的值发生变化的时候，就会触发这个handler，这是vue内部帮你做的事情
    //       this.applyList.map((r,index) => {
    //         if (this.form.number) {
    //           if (r.univalence) {
    //             let a =
    //               (Math.round(r.univalence * 100) / 100) *
    //               Math.round(this.form.number);
    //             this.$set(r,'total',Math.round(a * 100) / 1000000)
    //             if (this.maximumValue < r.total) {
    //               this.maximumValue = r.total;
    //             }
    //           } else {
    //             console.log(this.form+""+2)
    //             r.total = 0;
    //           }
    //         } else {
    //           console.log(this.form+""+3)
    //           r.total = 0;
    //         }
    //       });
    //       this.isUpdate = !this.isUpdate;
    //
    //   },
    //   deep: true, // 可以深度检测到 obj 对象的属性值的变化
    //   immediate: true //刷新加载  立马触发一次handler
    // }
  },
  methods: {
    async openPrintView(row) {
      const { data } = await getPurchaseParity(row.id);
      this.form = data;
      this.applyList = JSON.parse(data.parityList).map(item => {
        let pay_way = this.dict.type.pay_way.filter(item2 => {
          return item.payType == item2.value;
        })[0];
        console.log(pay_way);
        return {
          ...item,
          payTypeLabel: pay_way.label
        };
      });
      this.actBusinessStatus = data.actBusinessStatus;
      console.log(this.actBusinessStatus.createBy);
      const res = await getDept(this.actBusinessStatus.createBy);
      this.actBusinessStatus.deptName = res.data ? res.data.deptName : "";
      const res2 = await processApi.getHistoryInfoList(
        this.actBusinessStatus.processInstanceId
      );
      this.history = res2.data.reverse();
      // this.printView = true;
      this.printObject = [
        {
          tds: [
            {
              colspan: 1,
              align: "center",
              label: "项目名称"
            },
            {
              colspan: 3,
              align: "left",
              label: this.form.projectName
            },
            {
              colspan: 1,
              align: "center",
              label: "采购主体"
            },
            {
              colspan: 3,
              align: "left",
              label: this.form.payUnit
            }
          ]
        },
        {
          tds: [
            {
              colspan: 1,
              align: "center",
              label: "采购事项名称"
            },
            {
              colspan: 3,
              align: "left",
              label: this.form.itemName
            },
            {
              colspan: 1,
              align: "center",
              label: "期望交付日期"
            },
            {
              colspan: 3,
              align: "left",
              label: this.form.designDate
            }
          ]
        },
        {
          tds: [
            {
              colspan: 8,
              align: "center",
              label: "比价明细"
            }
          ]
        },
        {
          tds: [
            {
              colspan: 1,
              align: "center",
              label: "物品名称"
            },
            {
              colspan: 1,
              align: "center",
              label: "规格或型号"
            },
            {
              colspan: 1,
              align: "center",
              label: "供应商(款式)"
            },
            {
              colspan: 1,
              align: "center",
              label: "数量"
            },
            {
              colspan: 1,
              align: "center",
              label: "单价（元）"
            },
            {
              colspan: 1,
              align: "center",
              label: "总价（万元）"
            },
            {
              colspan: 1,
              align: "center",
              label: "付款方式"
            },
            {
              colspan: 1,
              align: "center",
              label: "交货期"
            }
          ]
        }
      ];
      let list = this.applyList.map(item => {
        return {
          tds: [
            {
              colspan: 1,
              align: "center",
              label: item.objectName
            },
            {
              colspan: 1,
              align: "center",
              label: item.specificationModel
            },
            {
              colspan: 1,
              align: "center",
              label: item.supplier
            },
            {
              colspan: 1,
              align: "center",
              label: item.number
            },
            {
              colspan: 1,
              align: "center",
              label: item.univalence + "元"
            },
            {
              colspan: 1,
              align: "center",
              label: item.total + "万元"
            },
            {
              colspan: 1,
              align: "center",
              label: item.payTypeLabel
            },
            {
              colspan: 1,
              align: "center",
              label: item.deliveryDate
            }
          ]
        };
      });
      this.printObject = this.printObject.concat(list);
      this.printObject.push({
        tds: [
          {
            colspan: 1,
            align: "center",
            label: "比价推荐说明"
          },
          {
            colspan: 7,
            align: "left",
            label: this.form.recommendedInstructions
          }
        ]
      });
      this.$refs.printForm.open();
    },
    /*日期范围控件选择完毕*/
    dateChanged() {
      if (this.form.startDate != null && this.form.endDate != null) {
        let val = dayjs(this.form.endDate).diff(
          dayjs(this.form.startDate),
          "days"
        );
        this.form.duration = val < 0 ? val : val + 1;
      }
    },
    /** 查询比价信息列表 */
    getList() {
      this.loading = true;
      listPurchaseParity(this.queryParams).then(response => {
        this.purchaseParityList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      this.getProjectList();
    },
    // 取消按钮
    cancel() {
      this.isdisabled = false;
      this.open = false;
      this.applyList = [{}];
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        purchaseType: undefined,
        projectName: undefined,
        objectName: undefined,
        specificationModel: undefined,
        number: undefined,
        createTime: undefined,
        updateTime: undefined,
        createBy: undefined,
        updateBy: undefined,
        payUnit: undefined,
        itemName: undefined,
        designDate: undefined,
        recommendedInstructions: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      //出差日期范围
      if (
        this.queryParams.tripTimeList != null &&
        this.queryParams.tripTimeList.length > 0
      ) {
        this.queryParams.startDate = this.queryParams.tripTimeList[0];
        this.queryParams.endDate = this.queryParams.tripTimeList[1];
      }
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.startDate = undefined;
      this.queryParams.endDate = undefined;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      if (selection.length == 1) {
        if (
          selection[0].actBusinessStatus.status == "draft" ||
          selection[0].actBusinessStatus.status == "back" ||
          selection[0].actBusinessStatus.status == "cancel"
        ) {
        } else {
          this.single = true;
        }
      }
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.flag = true;
      this.reset();
      this.open = true;
      this.title = "添加比价申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.flag = true;
      this.loading = true;
      this.reset();
      const id = row.id || this.ids;
      getPurchaseParity(id).then(response => {
        this.applyList = JSON.parse(response.data.parityList);
        this.loading = false;
        this.form = response.data;
        if (response.data.actBusinessStatus.createTime) {
          this.form.numberNum =
            this.processKey +
            "@" +
            parseTime(
              response.data.actBusinessStatus.createTime,
              "{y}{m}{d}{h}{i}{s}"
            );
        }
        this.$nextTick(() => {
          this.processInstanceId =
            response.data.actBusinessStatus.processInstanceId;
        });
        this.open = true;
        this.title = "修改比价申请";
      });
    },
    //查看
    handleView(row) {
      this.flag = false;
      this.loading = true;
      this.reset();
      const id = row.id || this.ids;
      getPurchaseParity(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.applyList = JSON.parse(response.data.parityList);
        if (response.data.actBusinessStatus.createTime) {
          this.form.numberNum =
            this.processKey +
            "@" +
            parseTime(
              response.data.actBusinessStatus.createTime,
              "{y}{m}{d}{h}{i}{s}"
            );
        }
        this.$nextTick(() => {
          this.processInstanceId =
            response.data.actBusinessStatus.processInstanceId;
        });
        this.isdisabled = true;
        this.open = true;
        this.title = "查看比价申请业务";
      });
    },
    /** 提交按钮 */
    submitForm(flag) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          this.form.parityList = JSON.stringify(this.applyList);
          if (this.form.id != null) {
            updatePurchaseParity(this.form)
              .then(response => {
                this.$modal.msgSuccess("修改成功");
                if (flag === "submit") {
                  this.submitFormApply(response.data);
                } else {
                  this.open = false;
                }
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          } else {
            addPurchaseParity(this.form)
              .then(response => {
                this.$modal.msgSuccess("新增成功");
                if (flag === "submit") {
                  this.submitFormApply(response.data);
                } else {
                  this.open = false;
                  this.cancel();
                }
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          }
        }
      });
    },
    // 提交成功回调
    submitCallback() {
      this.cancel();
      this.open = false;
      this.getList();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除比价信息编号为"' + ids + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delPurchaseParity(ids);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "oa/purchaseParity/export",
        {
          ...this.queryParams
        },
        `purchaseParity_${new Date().getTime()}.xlsx`
      );
    },
    //提交流程
    submitFormApply(entity) {
      //流程变量
      this.taskVariables = {
        entity: entity,
        maximumValue: this.maximumValue
      };
      const data = {
        processKey: this.processKey, // key
        businessKey: entity.id, // 业务id
        variables: this.taskVariables,
        classFullName: "com.ruoyi.oa.domain.OaPurchaseParity"
      };
      this.sendMessage = {
        title: "比价申请",
        messageContent: this.$store.state.user.nickName + "提交了比价申请"
      };
      // 启动流程
      processApi.startProcessApply(data).then(response => {
        this.taskId = response.data.taskId;
        this.$refs.verifyRef.visible = true;
        this.$refs.verifyRef.reset();
      });
    },
    //撤回
    cancelProcessApply(row) {
      this.$modal
        .confirm("是否撤销申请")
        .then(() => {
          this.loading = true;
          return processApi.cancelProcessApply(
            row.actBusinessStatus.processInstanceId
          );
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("撤回成功");
        })
        .finally(() => {
          this.loading = false;
        });
    },
    //添加表格里的行(申请状态)
    applayaddRow(tableData1) {
      tableData1.push({
        objectName: "",
        specificationModel: "",
        number: "",
        supplier: "",
        contactInformation: "",
        pileType: "",
        univalence: "",
        total: "",
        payType: "",
        deliveryDate: "",
        xh: this.xh1,
        infoId: this.infoId
      });
    },
    //删除表格里的行(申请状态)
    applaydeleteRow(index, rows) {
      rows.splice(index, 1);
    },
    getProjectList() {
      getProjectList().then(res => {
        this.projectNameList = res.data;
      });
    }
  }
};
</script>


<style lang="scss" scoped>
.main {
  width: 100%;
  height: 100%;
}
::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  width: 8px; /* 横向滚动条 */
  height: 8px; /* 纵向滚动条 必写 */
}
/* 设置滚动条样式 */
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  background-color: #dde;
  border-radius: 3px;
}
#selectForm >>> .el-form-item__label {
  font-size: 12px;
}
::v-deep .bjsm .el-form-item__content {
  width: calc(100% - 130px) !important;
}
</style>
